package sortTests;

import java.util.ArrayList;
import java.util.Collections;

public class MainSortTests {

	public static void main(String[] args) {
		/*BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		System.out.println("Enter array:");
		String arrayString = br.readLine();
		Scanner scanner = new Scanner(arrayString);
		ArrayList<Integer> array = new ArrayList<Integer>();
		
		while(scanner.hasNextInt()) {
			array.add(scanner.nextInt());
		}
		
		scanner.close();	*/	
		
		int stepSize = 10;
		int stepAmount = 5;
		
		System.out.println("n  bubble  heap  merge  quick");
		int size = 1;
		for (int i = 0; i < stepAmount; i++) {
			size *= stepSize;
			System.out.print(size+" ");
			
			BubbleSort bubble = new BubbleSort();
			System.out.print(measureSortTime(bubble, size)+" ");
			
			HeapSort heap = new HeapSort();
			System.out.print(measureSortTime(heap, size)+" ");
			
			MergeSort merge = new MergeSort();
			System.out.print(measureSortTime(merge, size)+" ");
			
			QuickSort quick = new QuickSort();
			System.out.println(measureSortTime(quick, size));
		}
		
	}

	private static long measureSortTime(ISorter sorter, int size) {
		ArrayList<Integer> array = new ArrayList<Integer>();
		for (int i = 0; i < size; i++) array.add(i);
		Collections.shuffle(array);
		long start = System.nanoTime();
		sorter.sort(array);
		long runTime = System.nanoTime() - start;
		return runTime;
	}
}
